package net.huashitong.scheduling.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.core.filter.Paging;

import net.huashitong.scheduling.entity.AreaRanking;
import net.huashitong.scheduling.filter.AreaRankingFilter;

@Repository
public class AreaRankingDao extends StringDao<AreaRanking> {
	
	public List<AreaRanking> queryAreaRankingList(AreaRankingFilter filter){
		GenericQuery query = createQuery("obj");
		query.append(" and industryId = :industryId").setParam("industryId",filter.getIndustryId());
		if("0".equals(filter.getState())){
			if(!"0".equals(filter.getAreaId())){
				query.append(" and date like:date").setParam("date", filter.getYear()+"%");
				query.append(" and areaId = :areaId order by cast(obj.cumulativeRanking as int) asc ").setParam("areaId",filter.getAreaId());
			}else{
				query.append(" and date like:date").setParam("date", filter.getYear()+"%");
				query.append(" and areaId = :areaId order by cast(obj.cumulative as int) desc ").setParam("areaId",filter.getAreaId());
				
			}
			
			
		}else if("1".equals(filter.getState())){
			if(!"0".equals(filter.getAreaId())){
				query.append(" and date like:date").setParam("date", filter.getYear()+"%");
				query.append(" and areaId = :areaId order by cast(obj.ratioRanking as int) asc ").setParam("areaId",filter.getAreaId());
			}else{
				query.append(" and date like:date").setParam("date", filter.getYear()+"%");
				query.append(" and areaId = :areaId order by cast(obj.ratio as int) desc ").setParam("areaId",filter.getAreaId());
			}
	
			
		}
		if("2".equals(filter.getAreaId())){
			return query.listResult(filter);
		}else{
			return query.listResult();
		}
		
	}
    
	public List<AreaRanking> queryIndustryName(AreaRankingFilter filter){
		GenericQuery query = createQuery("obj");
		query.append(" and date like:date").setParam("date", filter.getYear()+"%");
		query.append(" and areaId = :areaId GROUP BY industry_id ").setParam("areaId",filter.getAreaId());
		return query.listResult();
	}
}
